package com.zking.ssm.controller;

import com.zking.ssm.model.Book;
import com.zking.ssm.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/book")
public class BookController {
@Autowired
    private IBookService bookService;
@RequestMapping("/addBook")
public Map<String,Object> addBook(Book book){
bookService.insert(book);
return toJson("OK",null);
}
@RequestMapping("/queryBookAll")
public  Map<String,Object> queryBookAll(Book book){
    List<Book> books = bookService.queryBookAll(book);
    return toJson("OK",books);
}
private Map<String,Object> toJson(String msg,Object data){
    Map<String,Object> json=new HashMap<>();
    json.put("success",true);
    json.put("msg",msg);
    json.put("data",data);

    return  json;
}
}
